<html>
<head><meta charset="utf-8"><title>stack overflow handling · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stack.20overflow.20handling.html">stack overflow handling</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="237222767"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stack%20overflow%20handling/near/237222767" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stack.20overflow.20handling.html#237222767">(May 03 2021 at 20:22)</a>:</h4>
<p>/me wishes that current architectures had a mechanism to specifically define the stack range, so that you <em>can't</em> accidentally reference something outside the bounds of the stack, without using stack guard pages.</p>



<a name="237222860"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stack%20overflow%20handling/near/237222860" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stack.20overflow.20handling.html#237222860">(May 03 2021 at 20:23)</a>:</h4>
<p>with something like how Cranelift has special intra-stack-slot load/store instructions?</p>



<a name="237222877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stack%20overflow%20handling/near/237222877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stack.20overflow.20handling.html#237222877">(May 03 2021 at 20:23)</a>:</h4>
<p>and it takes an explicit operation to get a "global address"</p>



<a name="237223033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stack%20overflow%20handling/near/237223033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stack.20overflow.20handling.html#237223033">(May 03 2021 at 20:24)</a>:</h4>
<p>You'd be allowed to access things on the stack via a global address, but not access global things via a stack-relative address.</p>



<a name="237223134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stack%20overflow%20handling/near/237223134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stack.20overflow.20handling.html#237223134">(May 03 2021 at 20:25)</a>:</h4>
<p>And if you modified the stack pointer to be outside of the defined range (via sub, push, or anything else), you'd immediately get an error, rather than relying on a paging-based fault mechanism.</p>



<a name="237223137"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stack%20overflow%20handling/near/237223137" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stack.20overflow.20handling.html#237223137">(May 03 2021 at 20:25)</a>:</h4>
<p>right, so the separate instructions would allow this to be checked</p>



<a name="237223154"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stack%20overflow%20handling/near/237223154" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stack.20overflow.20handling.html#237223154">(May 03 2021 at 20:25)</a>:</h4>
<p>oooh magical register?</p>



<a name="237223178"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stack%20overflow%20handling/near/237223178" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stack.20overflow.20handling.html#237223178">(May 03 2021 at 20:25)</a>:</h4>
<p>not very RISC-y but certainly seems useful</p>



<a name="237223196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stack%20overflow%20handling/near/237223196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stack.20overflow.20handling.html#237223196">(May 03 2021 at 20:25)</a>:</h4>
<p>Right, this would only work on platforms that have the equivalent of either <code>ss</code> or <code>sp</code> or both.</p>



<a name="237223340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stack%20overflow%20handling/near/237223340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stack.20overflow.20handling.html#237223340">(May 03 2021 at 20:26)</a>:</h4>
<p>And if you're on a platform where this is a thing, you don't need to set up guard pages.</p>



<a name="237223381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stack%20overflow%20handling/near/237223381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Notification Bot <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stack.20overflow.20handling.html#237223381">(May 03 2021 at 20:27)</a>:</h4>
<p>This topic was moved here from <a class="stream-topic" data-stream-id="268952" href="/#narrow/stream/268952-edition-2021/topic/stack.20overflow">#edition 2021 &gt; stack overflow</a> by <span class="user-mention silent" data-user-id="239881">Josh Triplett</span></p>



<a name="237226540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stack%20overflow%20handling/near/237226540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stack.20overflow.20handling.html#237226540">(May 03 2021 at 20:49)</a>:</h4>
<p>I have been writing a compiler with stack overflow in mind, with the hopeful goal of eliminating the need for guard pages and stack probes, and one of the first issues I discovered is that it is not possible on linux to ensure that you don't stack overflow before you reach <code>_start</code>; someone can be very rude and put a bunch of crap in environment variables and also give you not much stack to work with, so you can literally stack overflow in a 100-byte hello world ELF</p>



<a name="237245210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stack%20overflow%20handling/near/237245210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stack.20overflow.20handling.html#237245210">(May 03 2021 at 23:15)</a>:</h4>
<p>This is exactly the kind of reason why I'd love to see hardware assistance there.</p>



<a name="237248814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stack%20overflow%20handling/near/237248814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stack.20overflow.20handling.html#237248814">(May 03 2021 at 23:59)</a>:</h4>
<p>/me wonders how pointer authentication could come into play here.</p>



<a name="237248892"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stack%20overflow%20handling/near/237248892" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stack.20overflow.20handling.html#237248892">(May 04 2021 at 00:00)</a>:</h4>
<p>This seems like a very special case of a mechanism that could be more general (e.g. buffer-overflow safe accesses)</p>



<a name="237249342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stack%20overflow%20handling/near/237249342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stack.20overflow.20handling.html#237249342">(May 04 2021 at 00:05)</a>:</h4>
<p>ARMv8-M Mainline has this I believe</p>



<a name="237256797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stack%20overflow%20handling/near/237256797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stack.20overflow.20handling.html#237256797">(May 04 2021 at 01:45)</a>:</h4>
<p><span class="user-mention" data-user-id="211727">@Jonas Schievink  [he/him]</span> Interesting! What does it look like there?</p>



<a name="237257196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stack%20overflow%20handling/near/237257196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stack.20overflow.20handling.html#237257196">(May 04 2021 at 01:51)</a>:</h4>
<p>Not sure if it's exactly what you're asking for but it has MSPLIM, which defines a stack pointer limit</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>